<?php

include "file_cache.php";
$cache = new JG_Cache('/usr/local/lxlabs/kloxo/httpdocs/hz_cache', 600);
$data = $cache->get($_GET['query']);

if($data == FALSE){
	mmseg_load_chars('../mmseg/data/chars.dic');
	mmseg_load_words('../mmseg/data/words-sogou.dic');
	mmseg_load_words('../mmseg/data/words-custom.dic');

	$text = $_GET['query'];

	$mmseg = mmseg_algor_create($text);

	$str = "";
	while ($token = mmseg_next_token($mmseg)) {
			$str .= $token['text'] . ",";
	}
	mmseg_algor_destroy($mmseg);

	include "curl_class.php";
	$url = 'http://hangzhoutuangou.appspot.com/search?query=' . $str;
	$cc = new cURL(); 
	$data =  $cc->get($url);
	if($data == FALSE){
		$data = '';
	}else{
		$cache->set($_GET['query'], $data);
	}
}

echo $data;
?> 
